package com.itheima02.controller;

import com.itheima02.domain.Student;
import com.itheima02.service.StudentService;
import com.itheima02.service.StudentServiceImpl;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;

public class StudentController {
    private StudentService service = new StudentServiceImpl();
    /*
        查询所有学生信息
     */
    @Test
    public void findAll() {
        ArrayList<Student> list = service.findAll();
        for (Student student : list) {
            System.out.println(student);
        }
    }

    /*
        条件查询，根据id查询学生信息
     */
    @Test
    public void findById() {
        Student stu = service.findById(3);
        System.out.println(stu);

    }

    /*
        添加学生信息
     */
    @Test
    public void insert() {
        Student student = new Student(5,"小周周",5,new Date());
        int res = service.insert(student);

        if(res!=0){
            System.out.println("添加成功！");
        }else {
            System.out.println("添加失败");
        }
    }

    /*
        修改学生信息
     */
    @Test
    public void update() {
        Student stu = new Student(5,"小周z",23,new Date());
        int res = service.update(stu);
        if(res!=0){
            System.out.println("修改成功！");
        }else {
            System.out.println("修改失败");
        }
    }

    /*
        删除学生信息
     */
    @Test
    public void delete() {
        int res = service.delete(2);
        if(res!=0){
            System.out.println("删除成功！");
        }else {
            System.out.println("删除失败");
        }
    }
}
